/** AGTC Edit Distance */
#include<cstdio>
#include<cstring>
#include<numeric>
#include<algorithm>
using namespace std;
const int maxn = 1007;
char x[maxn], y[maxn];
int n, m;
int dp[maxn][maxn];
int main() {
  while(scanf("%d%s%d%s", &n, x+1, &m, y+1)==4) {
    memset(dp, 0, sizeof(dp));
    for(int i=0; i<maxn; ++i) dp[i][0] = dp[0][i] = i;
    for(int i=1; i<=n; ++i) {
      for(int j=1; j<=m; ++j) {
        if(x[i]==y[j]) dp[i][j] = min(dp[i-1][j-1], min(dp[i-1][j]+1, dp[i][j-1]+1));
        else dp[i][j] = min(dp[i-1][j-1]+1, min(dp[i-1][j]+1, dp[i][j-1]+1));
      }
    }
    printf("%d\n", dp[n][m]);
  }
}